package com.axjy.service.impl;

import com.axjy.dto.InspectiontaskMainDto;
import com.axjy.mapper.InspectiontaskMainMapper;
import com.axjy.mapper.PoleInfoMapper;
import com.axjy.pojo.*;
import com.axjy.service.InspectiontaskMainService;
import com.axjy.service.vo.Pager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by 00 on 2018/2/25.
 */
@Service("InspectiontaskMain")
@Transactional
public class InspectiontaskMainServiceimpl implements InspectiontaskMainService {

    @Resource
    private PoleInfoMapper poleInfoMapper;
    @Resource
    private InspectiontaskMainMapper main;

    @Override
    public Pager xjzdfp(Integer offset, Integer limit, InspectiontaskMainDto dto) {
        Pager p=new Pager();
        p.setRows(main.xjzdfp(offset, limit, dto));
        p.setTotal(main.getCount(dto));
        return p;
    }

    @Override
    public void update(InspectiontaskMain inspectiontaskMain) {
        main.update(inspectiontaskMain);
    }



    @Override
    public void add(InspectiontaskMain inspectiontaskMain,Integer id) {
        System.out.println("==============");
        System.out.println("id="+id+"lineid="+inspectiontaskMain.getLineId()+"taksStatus="+inspectiontaskMain.getTaskStatus()+inspectiontaskMain.getLineCode()+inspectiontaskMain.getLineName());
        main.add(inspectiontaskMain);
        main.rwUpdate(id);
        List<PoleInfo> poleInfos = poleInfoMapper.selectSection(inspectiontaskMain.getStartPolecode(),inspectiontaskMain.getEndPolecode());
        for (PoleInfo p :
                poleInfos) {
            InspectiontaskDetail detail = new InspectiontaskDetail();
            detail.setTaskId(inspectiontaskMain.getId());
            detail.setTaskStatus(inspectiontaskMain.getTaskStatus());
            detail.setPoleId(p.getId());
            detail.setPoleCode(p.getPoleCode());
            detail.setLineCode(inspectiontaskMain.getLineCode());
            detail.setLineName(inspectiontaskMain.getLineName());

            main.zbadd(detail);
        }
        main.zbshow(inspectiontaskMain.getId());

    }



//    @Override
//    public List<InspectiontaskMain> zbshow() {
//        return main.zbshow();
//    }


    @Override
    public void delete(Integer isCancel, Integer id) {
        main.delete(isCancel, id);
    }

//    @Override
//    public void delete(Map<String, Object> ids) {
//        main.delete(ids);
//    }

    @Override
    public void fpUpdate(InspectiontaskMain inspectiontaskMain,Integer id) {
        main.rwUpdate(id);
        main.fpUpdate(inspectiontaskMain);
    }

    @Override
    public void fzrupdate(InspectiontaskMain inspectiontaskMain) {
        main.fzrupdate(inspectiontaskMain);
    }

//    @Override
//    public void rwUpdate(Integer id) {
//        main.rwUpdate(id);
//    }

    @Override
    public List<Systemconfig> search1() {
        return main.search1();
    }

    @Override
    public List<LineInfo> search2() {
        return main.search2();
    }

    @Override
    public List<User> search3() {
        return main.search3();
    }


}
